﻿namespace MicroCloud.Api.Systems.Areas.Admin.Controllers
{
    /// <summary>
    /// 模块包信息
    /// </summary>
    [Description("模块包信息")]
    [ModuleInfo(Code = "Pack", Name = "模块包信息", OrderNo = 2, Position = "Systems", PositionName = "系统管理模块")]
    public class PackController : AdminApiControllerBase
    {
        /// <summary>
        /// 读取模块包列表信息
        /// </summary>
        /// <param name="request">页请求</param>
        /// <returns></returns>
        [HttpPost]
        [ModuleInfo]
        [Description("读取")]
        public virtual PageData<PackOutputDto> Read(PageRequest request)
        {
            Check.NotNull(request, nameof(request));
            IFunction function = this.GetExecuteFunction();

            request.AddDefaultSortCondition(
                new SortCondition("Level"),
                new SortCondition("OrderNo")
            );
            Expression<Func<PackBase, bool>> exp = FilterService.GetExpression<PackBase>(request.FilterGroup);
            IServiceProvider provider = HttpContext.RequestServices;

            return CacheService.ToPageCache(provider.GetAllPacks().AsQueryable(), exp,
                request.PageCondition,
                m => new PackOutputDto()
                {
                    Name = m.Type.Name,
                    Display = m.Description,
                    Class = m.Type.FullName,
                    Level = m.Level,
                    OrderNo = m.OrderNo,
                    IsEnabled = m.IsEnabled
                },
                function).ToPageData();
        }

    }
}